package capricornus.actor.interactive
{
	import capricornus.actor.Actor;
	import capricornus.actor.events.ActorEvent;
	import capricornus.components.utils.FilterUtils;
	
	import flash.events.Event;

	public class ActorInteractiveController
	{
		protected var _actor:Actor;
		
		protected var _interactiveEnabled:Boolean = true;   //是否具有转化的鼠标交互事件
		
		public function ActorInteractiveController( actor:Actor )
		{
			_actor = actor;
			init();
		}
		
		private function init():void
		{
			_interactiveEnabled = true;
			_actor.addEventListener( ActorEvent.ACTOR_MOUSE_OVER, onMouseOver, false, 0, true );
			_actor.addEventListener( ActorEvent.ACTOR_MOUSE_OUT, onMouseOut, false, 0, true );
			_actor.addEventListener( ActorEvent.ACTOR_CLICK, onClick, false, 0, true );
		}
		
		public function set interactiveEnabled( value:Boolean ):void
		{
			if( _interactiveEnabled != value )
			{
				_interactiveEnabled = value;
				if( _interactiveEnabled )
				{
					init();
				}
				else
				{
					_actor.removeEventListener( ActorEvent.ACTOR_MOUSE_OVER, onMouseOver );
					_actor.removeEventListener( ActorEvent.ACTOR_MOUSE_OUT, onMouseOut );
					_actor.removeEventListener( ActorEvent.ACTOR_CLICK, onClick );
				}
			}
		}
		
		public function get interactiveEnabled():Boolean
		{
			return _interactiveEnabled;
		}
		
		private function onMouseOver( e:Event ):void
		{
			onActorMouseOver();
		}
		
		private function onMouseOut( e:Event ):void
		{
			onActorMouseOut();
		}
		
		private function onClick( e:Event ):void
		{
			onActorClick();
		}
		
		protected function onActorMouseOver():void
		{
			_actor.filters = FilterUtils.getGoldenGlowFilter();
		}
		
		protected function onActorMouseOut():void
		{
			_actor.filters = null;
		}
		
		protected function onActorClick():void
		{
			trace( "on actor click" );	
		}
	}
}